<?php
/** * 首页控制器 */
namespace Custom\Controller;
use Think\Controller;
class IndexController extends UserController {    
	function __construct()    {        
		parent::__construct();        
		$this->M_company = M('Company');        
		$this->s_id = session('s_id');    
	}    
	public function index(){        
		$account_id = $this->account_id;       
		 $acc_res = M('Account')->where("account_id = $account_id")->find();
		 $role_id = $acc_res['role_id'];        
		 if (session('is_son')==1) {            
		 	$RoleInfo = D('Role_son')->find($role_id);        
		 }else{            
		 	$RoleInfo = D('Role')->find($role_id);        
		 }        
		 $where = "is_menu=1 AND auth_pid=0 AND auth_id IN ({$RoleInfo['role_auth_ids']})";        
		 $this->topAuth = D('Auth')->getAuth($where);       
		 $where = "is_menu=1 AND auth_pid!=0 AND auth_id IN ({$RoleInfo['role_auth_ids']})";        
		 $this->sonAuth = D('Auth')->getAuth($where);        
		 if($this->s_id){            
		 	$info = M('store')->field('store_name')->find($this->s_id);            $this->assign('info',$info);            
		 	$session = $this->s_id;            
		 	$this->assign('session',$session);       
		 	 }        
		 	 $where = 'c_id='.$this->c_id;        
		 	 if($this->s_id && $acc_res['main']==1){           
		 	 	$where .= ' and s_id='.$this->s_id;        
		 	 }        
		 	 $data = M('store')->where($where)->field('s_id,store_name')->select();$this->assign('data',$data);     
		 	 $selectedStore = S('selectedStore'.$this->c_id);
		 	 if($selectedStore){
		 	 	session('s_id',$selectedStore);  
		 	 	$this->assign('selectedStore',$selectedStore);  
		 	 } 
		 	 $this->display();    
		 	}        
	/*     * 存s_id进session     */    
	public function sel(){
		$s_id = (int)$_GET['s_id'];
		$data = M('store')->where("s_id=$s_id AND c_id=$this->c_id")->find();
		if($data){
			S('selectedStore'.$this->c_id,$s_id);
			session('s_id',$s_id);  
			if($s_id){            
				$this->ajaxReturn(array('result'=>'tp1'));        
			}    
		}else{
			die('非法登录');
		}
		      
	}
    //主页轮询查找新订单
    public function checkNewOredre(){
    	if(!$this->s_id){
    		echo json_encode(array('status'=>1));
    		die();
    	}
        $newOrder = S("newOrder$this->s_id");
        if($newOrder){
             //有新订单
             echo json_encode(array('status'=>0,'data'=>$newOrder));
        }else{
             echo json_encode(array('status'=>1));
        }
    }
    public function setOldOrder(){
    	S("newOrder$this->s_id",null);
    }
}